<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>资源管理</title>
    <%@include file="/WEB-INF/jsp/common/meta2.jsp" %>
</head>
<body class="content-body">
<div class="container-fluid">

    <table class="table table-responsive table-bordered">
        <tr>
            <th colspan="20" class="bg-info text-center">系统用户编辑</th>
        </tr>
        <tr>
            <td>
                <form id="inputForm" action="${ctx}/common/user/save" method="post"
                      class="form-horizontal col-sm-offset-2 col-sm-8" role="form">
                    <input name="id" value="${entity.id}" id="id" type="hidden"/>

                    <c:if test="${entity.id != 1}">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">账号：</label>

                            <div class="col-sm-4">
                                <input type="text" name="userName" id="userName" value="${entity.userName}"
                                       placeholder="账号" class="form-control input-sm">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">昵称：</label>

                            <div class="col-sm-4">
                                <input type="text" name="nickName" id="nickName" value="${entity.nickName}"
                                       placeholder="昵称" class="form-control input-sm">
                            </div>
                        </div>
                        <c:if test="${entity.password == null}">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">密码：</label>

                                <div class="col-sm-4">
                                    <input type="text" name="password" id="password" value="" maxlength="20"
                                           placeholder="密码" class="form-control input-sm">
                                </div>
                            </div>
                        </c:if>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">角色：</label>

                            <div class="col-sm-8">
                                <c:forEach items="${roles}" var="role">
                                    <label class="radio-inline">
                                        <input type="radio" name="role"
                                               value="${role.id}" ${entity.role == role.id ?'checked':''}>${role.name}
                                    </label>
                                </c:forEach>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">禁用：</label>

                            <div class="col-sm-8">

                                <label class="radio-inline">
                                    <input type="radio" name="enable" value="true" ${entity.enable? 'checked':''}> 是
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="enable" value="false" ${entity.enable? '':'checked'}> 否
                                </label>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">备注：</label>

                            <div class="col-sm-8">
                                <textarea class="form-control" rows="8" name="memo">${entity.memo}</textarea>
                            </div>
                        </div>
                    </c:if>

                    <div class="form-group">
                        <div class="col-sm-offset-4 col-sm-8">
                            <input type="submit" value="确定" class="btn btn-info btn-sm">
                            <input class="btn btn-warning btn-sm" onclick="history.go(-1);" type="button"
                                   value="返回"/>
                        </div>
                    </div>


                </form>

            </td>
        </tr>
    </table>
</div>

</body>
</html>

<script>
    $(function () {
        $("#inputForm").validate({
            rules: {
                nickName: {
                    required: true,
                    maxlength: 20
                },
                password: {
                    required: true,
                    maxlength: 20,
                    minlength: 6
                },
                userName: {
                    required: true,
                    maxlength: 30,
                    minlength: 3,
                    remote: {
                        type: "POST",
                        url: "${ctx}/common/user/repeat/account",
                        beforeSend: function (xhr) {
                            top.loadingModal.stop = true;
                        },
                        complete: function (xhr, status) {
                            top.loadingModal.stop = false;
                        },
                        data: {
                            id: $("#id").val(),
                            code: function () {
                                return $("#userName").val().trim();
                            }
                        }
                    }
                },
                role: {
                    required: true
                },
                memo: {
                    maxlength: 500
                }
            },
            messages: {
                userName: {
                    remote: "用户账号已经存在！"
                }
            }
        });


    });


</script>
